class FooError extends Error {
	constructor(...args) {
        super(...args)
        Error.captureStackTrace(this, FooError)
    }
}

function foo(x) {
	if (x) {
		throw new FooError('there was a problem')
	} else {
		return 1024
	}
}

function bar() {
	try {
		foo(1)
	} catch (e) {
		if (e instanceof FooError) {
			console.dir(e)
		} else {
			console.dir(e)
		}
	}
}

bar()
